﻿using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Brjnk.Common;
using Brjnk.GpxExplorer.Workspace.Searching;

namespace Brjnk.GpxExplorer.UI
{
    /// <summary>
    /// Interaction logic for SearchPositionWindow.xaml
    /// </summary>
    public partial class SearchPositionWindow : Window, INotifyPropertyChanged
    {
        private SearchService service;

        public SearchPositionWindow(SearchService service)
        {
            InitializeComponent();
            this.service = service;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
        }

        private GpsCoordinates coordinates;

        public GpsCoordinates Coordinates
        {
            get { return coordinates; }
            set { coordinates = value; OnPropertyChanged("Coordinates"); }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (argsEditor.LimitValidationFailed || Validation.GetHasError(coordinatesTxb))
                return;
            service.SearchedItems.Add(new SearchPositionRequest()
                {
                    MaxDistance = argsEditor.Limit,
                    ShowAgainDistance = argsEditor.SearchAgainLimit,
                    Position = Coordinates,
                    SearchInGaps = argsEditor.SearchInGaps,
                    Color1 = colorPicker.Color,
                    Color2 = Colors.Black
                });

            this.DialogResult = true;
        }
    }
}